import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2024-06-29
 * Time: 16:11
 */
public class Deom4 {
    public static void main(String[] args) throws IOException {
        //版本1：无参数一个一个的从文件中读到程序中
        /*try(Reader reader = new FileReader("./text.txt")) {
            while(true) {
                int a = reader.read();
                if(a == -1) {
                    break;
                }
                char ch = (char) a;
                System.out.println(ch);
            }
        }*/
        //版本2：带一个参数的，参数类型为char[]
        /*try(Reader reader = new FileReader("./text.txt")) {
            char[] ch = new char[1024];
                int a = reader.read(ch);
            for (int i = 0; i < a; i++) {
                System.out.println(ch[i]);
            }
        }*/
        //版本3：带三个参数 分别为参数类型char[],int off,int len
        try(Reader reader = new FileReader("./text.txt")) {
            char[] ch = new char[1024];
            int a = reader.read(ch,0,2);
            for (int i = 0; i < a; i++) {
                System.out.println(ch[i]);
            }
        }
    }
}
